package com.oauth.service.generic;


import org.springframework.util.StringUtils;

import com.oauth.service.generic.beans.OAuthServiceBean;
import com.oauth.service.generic.dao.OAuthDAO;
import com.oauth.service.generic.exception.OAuthServiceException;

public class OAuthServiceImpl implements OAuthService {

	private OAuthDAO mOAuthDAO;

	@Override
	public <T extends OAuthServiceBean> void deleteToken(Long pMemberId,Class<T> pClass) {
			mOAuthDAO.deleteToken(pMemberId,pClass);
	}

	@Override
	public <T extends OAuthServiceBean> T getToken(Long pMemberId,Class<T> pClass) {
		return mOAuthDAO.getToken(pMemberId,pClass);
	}


	@Override
	public <T extends OAuthServiceBean> T persistToken(T serviceBean) throws OAuthServiceException {
		if (serviceBean == null
				|| serviceBean.getMemberId() == null
				|| !StringUtils.hasText(serviceBean.getAccessToken())
				|| !StringUtils.hasText(serviceBean.getAccessTokenSecret())) {
			throw new OAuthServiceException("Parameters are null" + serviceBean);
		}
		return  mOAuthDAO.persistToken(serviceBean);
	}

	/**
	 * @param pOAuthDAO the oAuthDAO to set
	 */
	public void setoauthDAO(OAuthDAO pOAuthDAO) {
		mOAuthDAO = pOAuthDAO;
	}

}